<style scoped src="./index.scss" lang="scss" rel="stylesheet/scss"></style>
<template src="./index.html"></template>
<script>
export default {
  mixins: [Vue.prototype.$vFN.Mixins.Base, Vue.prototype.$vFN.Mixins.Edit],
  components: {
    SelectDataStore: async () =>
      Vue.extend(
          await Vue.prototype.$vFN.Components.Base.SelectDataStore()
      ),
  },
  data() {
    return {
      appWindow: window,
      form: {
        store_id: null,
        ratio: "",
      },

      storeList: [],

      editVisible: false,
    };
  },
  methods: {
    SelectDataStore() {
      this.$vFN.Directives.SelectDataStore({
        appWindow: this.appWindow,
        selectIds: this.storeList,
        apiConfig: this.$vFN.Tools.getAppGlobalData('componentsApiConfig.SelectStore', window),
        count: 1,
        onSuccess: (res) => {
          this.storeList = res;
        },
      });
    },

    async sum() {
      let res = await this.$vFN.Http.post({
        url: this.editType == 'add' ? "plugin/team-dividend/admin/store/add" : "plugin/team-dividend/admin/store/amend",
        data: {
          store_id: this.editType == 'add' ? this.storeList[0] : this.id,
          ratio: this.form.ratio,
        }
      }, window);
      if(res.code == 200) {
        this.$vFN.Tools.messageSuccess("操作成功");
        this.editVisible = false;
        this.onSuccess();
      }
    },

    // 初始化
    async init() {
      if(this.editType == 'update') {
        this.form.ratio = this.ratio;

      }
      this.editVisible = true;
      this.load = false;
    },
    // 成功回调
    onSuccess() {},
    // 取消回调
    onCancel() {
      this.editVisible = false;
    },
    // 失败回调
    onError() {},
  },
  mounted() {
    this.init();
  },
  activated() {},
};
</script>